﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Linq.Expressions;
using TelerikedIn.Models;

namespace TelerikedIn.WebApp.ViewModels.Account
{
    public class UpdateProfileVM
    {
        public string Id { get; set; }

        [Required, StringLength(100)]
        [Display(Name = "First Name")]
        public string FirstName { get; set; }

        [Required, StringLength(100)]
        [Display(Name = "Last Name")]
        public string LastName { get; set; }

        [StringLength(100)]
        [Display(Name = "Home City")]
        public string City { get; set; }

        [StringLength(100)]
        [Display(Name = "Country")]
        public string Country { get; set; }

        [StringLength(100)]
        [Display(Name = "Education type.")]
        public string Education { get; set; }

        public string Image { get; set; }

        public static Expression<Func<ApplicationUser, UpdateProfileVM>> FromUser
        {
            get
            {
                return user => new UpdateProfileVM 
                {
                    Id = user.Id,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    City = user.City,
                    Country = user.Country,
                    Education = user.Education,
                    Image = user.Image != null ? Convert.ToBase64String(user.Image) : null
                };
            }
        }

        public ApplicationUser ToUser
        {
            get 
            {
                return new ApplicationUser 
                {
                    Id = this.Id,
                    FirstName = this.FirstName,
                    LastName = this.LastName,
                    City = this.City,
                    Country = this.Country,
                    Education = this.Education                    
                };
            }
        }
    }
}